package implementation.sort;

import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;
import implementation.sort.AbstractSorter;

import java.util.Comparator;
import java.util.List;


public class SelectionSort extends AbstractSorter {

    public SelectionSort() {
        super(SorterType.SELECTION);
    }


    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        int min;
        for (int j = 0; j < ts.size(); j++) {
            min = j;
            for (int i = j + 1; i < ts.size(); i++) {
                if (greater(tComparator, ts, min, i)) {
                    min = i;
                }
            }
            swap(ts, j, min);
        }
    }
}
